package com.compose.skia;

import android.view.Surface;

public class JSApp {

    private long pointer;
    private String jsCode;

    public static synchronized JSApp createApp(String jsCode) {
        JSApp app = new JSApp(jsCode);
        app.pointer = app.createNativeJsApp();
        return app;
    }

    private JSApp(String jsCode) {
        this.jsCode = jsCode;
    }

    public void onStart() {
        start();
    }

    public void onStop() {
        stop();
    }

    public void onDestroy() {
        destroy();
        destroyNativeJsApp(pointer);
    }

    public void onPause() {
        halt();
    }

    public void onResume() {
        resume();
    }

    public void onAttachSurface(Surface surface, int width, int height) {
        attachSurface(surface, width, height);
    }

    public void onDetachSurface(Surface surface) {
        detachSurface(surface);
    }

    public String getJSAppCode() {
        return jsCode;
    }

    private native long createNativeJsApp();

    private native void destroyNativeJsApp(long pointer);

    public native void start();

    public native void stop();

    public native void destroy();

    public native void halt();

    public native void resume();

    public native void attachSurface(Surface surface, int width, int height);

    public native void detachSurface(Surface surface);
}
